<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 *
 * Smarty {restaurant_type_4} function plugin
 * @param array|null $params
 * @param Smarty $smarty
 */
function smarty_function_restaurant_type_4($params, $smarty) {
    if (!isset($params)) {
        return ;
    }

    if (isset($params['limit'])) {
        $limit = $params['limit'];
    } else {
        $limit = 4;
    }
	
	$filters = array('limit' => $limit, 'page' => $params['page']);
	
	$pref = ($smarty->CI->uri->segment(2)) ? $smarty->CI->uri->segment(2) : 'ca-nuoc';
	if($pref != 'ca-nuoc')
	{
		$filters['pref_alias'] = $pref;
	}
    

    $smarty->CI->load->model('restaurant/restaurant_model');
    $data = $smarty->CI->restaurant_model->get_restaurants($filters);
    if (!$data) {
        return '';
    }

    $ci =& get_instance();
    $ci->load->helper('text');
    $html = '';
    foreach ($data as $item) {
        $intro = word_limiter($item['introtext'], 40);
        $html .= "<div class='restaurant_local_basic'>
                <div class='restaurant_local_basic_header'>
                    <a href='{$item[link]}' title='{$item[name]}'>
                        <img src='{$item[image4]}' alt='{$item[name]}' title='{$item[name]}'>
                    </a>
                </div>
                <div class='restaurant_local_basic_content'>
                    <div class='title'>
                        <a href='{$item[link]}' title='{$item[name]}'> {$item[name]}</a>
                    </div>
                    <p>
                        {$intro}
                    </p>
                </div>
                <div class='restaurant_local_basic_address'>
                    {$item[address]}, {$item[pref_name]}
                </div>
            </div>";
    }
    return $html;
}
